//index.js
const config = require('../../config.js')
const http = require('../../http.js')
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    page:1,
    pageSize:10,
    defaultUrl:'',
  },
   

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList();
    var that = this;
    wx.getSystemInfo( {
      success: function( res ) {
          that.setData( {
              winWidth: res.windowWidth,
              winHeight: res.windowHeight
          });
      }

  });
  },
//  tab切换逻辑
swichNav: function( e ) {
  var that = this;
  if( this.data.currentTab === e.target.dataset.current ) {
      return false;
  } else {
      that.setData( {
          currentTab: e.target.dataset.current
      })
  }
},

play:function(e){
  var that = this;
  let playSrc = e.currentTarget.dataset.src;
  that.setData({
    playSrc: playSrc
})
},
bindChange: function(e) {
  var that = this;
  that.setData( { currentTab: e.detail.current });
},
  getList: function () {
    var that = this
    http.request(
      config.openClass+"/"+this.data.page+"/"+this.data.pageSize,
      'get', null,
      function (res) {
        if (res.data!= null) {
          that.setData({
              listData: res.data,
              playSrc:res.data[0].resources
          })
        }
      },
      function (err) {
        wx.showToast({
            title: "数据加载失败！",
            icon: 'none',
          })
      } )
  },
})